const PredictTheWinner = (nums) => {
  const len = nums.length;
  const memo = Array.from(new Array(len), () => new Array(len));
  const helper = (i, j) => {
    if (i == j) return nums[i];
    if (memo[i][j] !== undefined) {
      return memo[i][j];
    }
    const pickI = nums[i] - helper(i + 1, j);
    const pickJ = nums[j] - helper(i, j - 1);
    memo[i][j] = Math.max(pickI, pickJ);
    return memo[i][j];
  };
  return helper(0, len - 1) >= 0;
};
